<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ page import="com.beaut.project.util.StaticData" %>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");
    String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
	String gd_status = request.getParameter("gd_status") == null ? "" : request.getParameter("gd_status");
	String gd_content_code = request.getParameter("gd_content_code") == null ? "" : request.getParameter("gd_content_code");
	String gd_content_num = request.getParameter("gd_content_num") == null ? "" : request.getParameter("gd_content_num");
	String gd_type = request.getParameter("gd_type") == null ? "" : request.getParameter("gd_type");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
%>
<html>
	<head>
		<title>现场交底</title>
	</head>
	<script type="text/javascript">
	  var gd_type="<%=gd_type%>";
	$(function(){
			var gd_status="<%=gd_status%>";	
		  
			$("#table").datagrid({
				title:"现场交底",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				
				url:'<%=contextPath %>/springMVC/gd/listPageGDDescription?gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'交底时间',field:'description_time',width:100,align:'center'},
					{title:'交底内容',field:'content',width:200,align:'center'},
					{title:'交底方',field:'description_person_name',width:100,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:100,align:'center'},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditGdDescription(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteGDDescription('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditGdDescription(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
						}
						if(gd_type==0){
							
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditGdDescription(2,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
						      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_JD_SHENPI%>")+"','"+rowData.id+"');\"/>";
						}else{
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditGdDescription(2,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
						      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_JD_SHENPI_W%>")+"','"+rowData.id+"');\"/>";
							
						}
                    	
	
					}}
				]],
				toolbar:
				[{
						id:'add',
						text:'新增',
						iconCls:"icon-add",
						handler:function(){
							addOrEditGdDescription(0);
						}
					},
					{
						id:'jdwc',
						text:'交底完成',
						iconCls:"icon-ok",
						handler:function(){
							updateGDBaseWork();
						}
					}
				],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					$("#add").hide();
					$("#jdwc").hide();
					if(parseInt('<%=gd_content_num%>') > 1){
						//表示有多个内容
						if("<%=StaticData.DESCRIPTION_ADD %>" == gd_status||"<%=StaticData.DESCRIPTION_ADD %>"==gd_status){
							if('<%=gd_content_num%>' == '<%=gd_content_code%>'){
								$("#add").show();
								$("#jdwc").show();
							}
						}
					}else{
						if("<%=StaticData.DESCRIPTION %>" == gd_status||"<%=StaticData.DESCRIPTION_ADD %>"==gd_status){
							$("#add").show();
							$("#jdwc").show();
						}
					}
					
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function deleteGDDescription(gd_description_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdDescritpion",
						data:"gd_description_id="+gd_description_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function updateGDBaseWork(){
			$.messager.confirm('确认','您确定要完成交底吗？',function(msg){
				if(!msg){
					return false;
				}else{
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/updateGDBaseWork",
						data:"gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&person_id=<%=person_id%>",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								eval('window.opener.rtCallBack();');
								window.close();
							}
							else if(rtJson.rtState == '2'){
								warningInfo(rtJson.rtMsrg);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function addOrEditGdDescription(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditGdDescription.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&gd_name=<%=gd_name%>&gd_code=<%=gd_code%>",1000, 800);
			}else if(type==1){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditGdDescription.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&gd_name=<%=gd_name%>&gd_code=<%=gd_code%>&gd_description_id="+id,1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/gd/addOrEditGdDescription.jsp?isShow=1&gd_description_id='+id+'&gd_name=<%=gd_name%>&gd_code=<%=gd_code%>',1000, 800);	
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		
		function shenpi(obj,gd_description_id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/gd/addOrEditGdDescription.jsp?isShow=1&callback=rtCallBack&gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&gd_name=<%=gd_name%>&gd_code=<%=gd_code%>&gd_description_id="+gd_description_id;
	      var param="";
	      if(gd_type==0){
	    	  param= "flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_JD_SHENPI%>")+"&businessId="+gd_description_id;
	      }else{
	    	  param= "flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_JD_SHENPI_W%>")+"&businessId="+gd_description_id;
	      }
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
	</script>
	<body>
		<div id="table" data-options="fit:true" ></div>
		<div id="addWindow" class="easyui-window" title="添加菜单" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:400px;padding:10px;">
	    	<table>
	    		<tr>
	    			<td>text(123):</td>
	    			<td><input  type="text" name="text" ></input></td>
	    		</tr>
	    	</table>
		</div>
	</body>
</html>
